#!/bin/bash
# Qemu helper script

# Save as a .sh file (e.g. qemuh.sh)
# Run chmod +x qemuh.sh

# ISO path input
echo "Please enter the ISO path:"
read cdrom

# RAM input
echo $'\n'"(Optional) Amount of RAM (default: 1024M):"
read ramamount

# Hard disk image input
echo $'\n'"(Optional) Hard disk image (e.g. test.img):"
read hdimage

# Prepare the Qemu command based on input
qemu_command="qemu-system-"$(uname -m)
qemu_command="$qemu_command -net nic -net user -soundhw all -machine accel=kvm"
if [ -n "$cdrom" ]; then
	qemu_command="$qemu_command -cdrom $cdrom"
fi
if [ -n "$ramamount" ]; then
	qemu_command="$qemu_command -m $ramamount"
elif [ ! -n "$ramamount" ]; then
	qemu_command="$qemu_command -m 1024M"
fi
if [ -n "$hdimage" ]; then
	qemu_command="$qemu_command -hda $hdimage"
fi
if [ -f /dev/kvm ]; then
	qemu_command="$qemu_command -machine accel=kvm"
fi

# Process command line parameters
while getopts s: option
do
case "${option}"
in
	s) echo "#!/bin/bash"$'\n'"$qemu_command">> ${OPTARG};chmod +x ${OPTARG};;
esac
done

# Run the Qemu command
echo $'\n'"Running command:"$'\n'"$qemu_command"
eval $qemu_command
